package controllers;

import models.Event;
import models.Task;
import play.cache.Cache;
import play.mvc.Controller;
import play.mvc.With;

/**
 * Created by IntelliJ IDEA.
 * User: bicho
 * Date: 29/01/12
 * Time: 10:30
 * To change this template use File | Settings | File Templates.
 */
@With(Secure.class)
public class ManageEventPageController extends Controller {

    public static void manageEvent(String nick) {
        if (!Security.check(Task.GESTION_EVENTO + "|" + nick)) {
            forbidden();
        } else {
            Event event = Event.getByNick(nick);
            render(event);
        }
    }

    public static void save(String nick, Event event) {
        if (!Security.check(Task.GESTION_EVENTO + "|" + nick)) {
            forbidden();
        } else {
            Event eventbyNick = Event.find("byNick", nick).first();
            eventbyNick.name = event.name;
            eventbyNick.description = event.description;
            eventbyNick.nick = event.nick;
            eventbyNick.isActive = event.isActive;
            eventbyNick.dateBegin = event.dateBegin;
            eventbyNick.dateEnd = event.dateEnd;
            eventbyNick.address = event.address;
            eventbyNick.save();
            Cache.set(nick + "event", event);
            flash.success("Se actualizó el evento");
            EventPageController.show(nick);
        }
    }


}
